package com.nbsaas.boot.queue.task;

import java.time.LocalDateTime;
import java.util.UUID;

public abstract class AbstractTask implements Task {
    private final String id;
    private final LocalDateTime executeTime;
    private final int priority;
    private final int maxRetries;
    private final long retryInterval;
    private final String[] dependencies;
    private TaskStatus status;
    private int currentRetries;
    private TaskMetadata metadata;

    protected AbstractTask(LocalDateTime executeTime, int priority, int maxRetries, long retryInterval, String[] dependencies) {
        this.id = UUID.randomUUID().toString();
        this.executeTime = executeTime;
        this.priority = priority;
        this.maxRetries = maxRetries;
        this.retryInterval = retryInterval;
        this.dependencies = dependencies;
        this.status = TaskStatus.PENDING;
        this.currentRetries = 0;
        this.metadata = new TaskMetadata();
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public LocalDateTime getExecuteTime() {
        return executeTime;
    }

    @Override
    public int getPriority() {
        return priority;
    }

    @Override
    public TaskStatus getStatus() {
        return status;
    }

    @Override
    public void setStatus(TaskStatus status) {
        this.status = status;
    }

    @Override
    public int getMaxRetries() {
        return maxRetries;
    }

    @Override
    public int getCurrentRetries() {
        return currentRetries;
    }

    @Override
    public void incrementRetries() {
        this.currentRetries++;
    }

    @Override
    public long getRetryInterval() {
        return retryInterval;
    }

    @Override
    public String[] getDependencies() {
        return dependencies;
    }

    @Override
    public TaskMetadata getMetadata() {
        return metadata;
    }

    @Override
    public void setMetadata(TaskMetadata metadata) {
        this.metadata = metadata;
    }
} 